/***************************************************************************
 创建者: 华磊
 开始时间: 2019.2.25
 copyright: (C) 华友高科
 修改说明: (每次有修改就添加一条，带有 修改人，修改时间，修改描述)
 example (1) 李文友 2017.5.8 类的具体实现代码编写

 ***************************************************************************
 *  @file x.h
 *  功能: 检测二维码位置功能
 *
 *                                                                         *
 ***************************************************************************/

#ifndef QRCODEDETECT_H
#define QRCODEDETECT_H
#include <QString>
#include <QMap>
#include "opencv2/imgproc/imgproc.hpp"
#include "opencv2/core/core.hpp"
#include "opencv2/highgui/highgui.hpp"

using namespace std;
using namespace cv;
//namespace cv{
//class VideoCapture;
//}
//namespace cv{
//class Point;
//}
//namespace cv{
//class Mat;
//}
class QrcodeDetect
{
public:
    QrcodeDetect(double allowMinAreaIn,double allowMaxAreaIn,double allowMinLengthIn,
                 double allowMaxLengthIn, double colorThreholdIn);
public:
    /**
     * @brief detectQrcode
     * @param videoDeviceId 视频设备ｉｄ,一般从０开始
     * @param xOut pix
     * @param yOut pix
     * @param rOut rad弧度
     * @param featureNumOut　特征方块的个数
     * @return －１００：设备没有打开，0:没有获取到图像帧，１正常识别到二维码。－１图片二维码识别失败
     */
    int detectQrcode(int videoDeviceId,double &xOut,double &yOut,double &rOut,int &featureNumOut);
    int detectQrcode(QString filePath, double &xOut, double &yOut, double &rOut, int &featureNumOut);
    int detectQrcode(cv::Mat srcImage, double &xOut, double &yOut, double &rOut, int &featureNumOut);
    int showDebugWindow(int id);
    int setDetectParameter(double allowMinAreaIn,double allowMaxAreaIn,double allowMinLengthIn,
                           double allowMaxLengthIn,double colorThreholdIn);
private:
    Point center_cal(vector<vector<Point> > contours, int i);
    Point2d center_cal_pricise(vector<vector<cv::Point> > contours,int i);//int的精度不够，１个像素转换为角度差了１度左右
    int calculateQrcodeLocation(vector<vector<cv::Point> > contours,double &xOut,double &yOut,double &rOut);

private:
    pthread_mutex_t matchMutex;
    pthread_mutexattr_t matchAttr;
    int debugFlag;
    QMap<int,cv::VideoCapture*> deviceMap;

    double allowMinArea;
    double allowMaxArea;
    double allowMinLength;
    double allowMaxLength;
    double colorThrehold;

    int camera_width;
    int camera_height;
    int camera_fps;

};

#endif // QRCODEDETECT_H
